package com.andkrup.web.components {

	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import com.andkrup.web.components.IComponent;
	
	/**
	 * @author Andkrup
	 */
	public class Component extends Sprite implements IComponent {
		protected var components:Array;
		
		public function get displayObject():DisplayObject {
			return this;
		}
		
		public function Component() {
			components = [];
		}
		
		public function hasComponent(component : IComponent) : Boolean {
			var l:int = components.length;
			for(var i:int = 0; i < l;i++){
				if(components[i]==component){
					return true;
				}
			}
			return false;
		}
		
		public function addComponent(component : IComponent) : void {
			if(hasComponent(component)) return;
			components.push(component);
		}
		
		public function removeComponent(component : IComponent) : void {
			var l:int = components.length;
			for(var i:int = 0; i < l;i++){
				if(components[i]==component){
					components.slice(i,1);
				}
			}
		}
		
		public function init(data : *) : void {
			throw new Error("abstract method - please override");
		}
		
		public function kill() : void {
			throw new Error("abstract method - please override");
		}
	}
}
